# -*-coding: Utf-8 -*-
# @File : case
# author: liaohf
# Time：2024/9/22
from core.Response import success, fail
from database.models.base import CaseStats
from schemas import case
from fastapi import APIRouter

router = APIRouter()


@router.post("/addCaseStats", summary="用例结果添加")
async def add_case_stats(post: case.AddCaseStats):
    """
    用例结果添加
    :param post: case.CaseStats
    :return:
    """
    # 添加日志
    sql_add_case_stats = await CaseStats.create(**post.dict())
    if not sql_add_case_stats:
        return fail(msg=f"用例结果添加失败!")
    return success(msg=f"用例结果添加成功!")


@router.get("/getCaseStatsListByProjectRunId", summary="获取用例结果")
async def get_case_stats(project_run_id):
    """
    用例结果添加
    :param project_run_id
    :return:
    """
    # 添加日志
    sql_get_case_stats = await CaseStats.filter(project_run_id=project_run_id).all()
    if not sql_get_case_stats:
        return fail(msg=f"用例结果获取失败!")
    return success(msg=f"用例结果获取成功!", data=sql_get_case_stats)
